//
//  RegisterViewController.m
//  拉勾7.17
//
//  Created by 殷殷明静 on 16/7/17.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "RegisterViewController.h"

@interface RegisterViewController ()

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor brownColor];
    // 背景imageView
    self.backgroundImageView = [UIImageView createBackgroundImageVIew];
    [self.view addSubview:_backgroundImageView];
    // 加一层毛玻璃
    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:1];
    UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
    effectview.frame = CGRectMake(0, 0, _backgroundImageView.frame.size.width, _backgroundImageView.frame.size.height);
    [_backgroundImageView addSubview:effectview];
    
    // 拉勾icon
    self.lagouIcon = [UIImageView createLaGouIcon];
    [self.view addSubview:_lagouIcon];
    
    // personTextField
    // 改变光标颜色(所有textField全改变)
    [[UITextField appearance] setTintColor:COLOR1];
    self.personTextfield = [CustomTextField createPersonTextFieldOnLoadPage];
    [self.view addSubview:_personTextfield];
    [_personTextfield.personImageView setImage:[UIImage imageNamed:@"icon_iphone1"]];
    _personTextfield.placeholder = @"请输入手机号";
    
    // passwordTextfield
    self.passwordTextfield = [CustomIdentifyPhoneNumberTextField createPasswordTextFieldOnLoadPageWithRightView];
    [self.view addSubview:_passwordTextfield];
    [self.passwordTextfield.phoneImageView setImage:[UIImage imageNamed:@"icon_identify1"]];
    _passwordTextfield.placeholder = @"请输入验证码";
    
    // forgotPasswordButton;
    self.forgotPasswordButton = [UIButton createForgotPassword];
    [self.view addSubview:_forgotPasswordButton];
    [_forgotPasswordButton setTitle:@"拉钩用户协议" forState:0];
    _forgotPasswordButton.frame = CGRectMake(WIDTH - 20 - 80 - 40, 450, 120, 50);
    [_forgotPasswordButton setTitleColor:COLOR1 forState:0];
    _forgotPasswordButton.backgroundColor = [UIColor clearColor];
    // 忘记密码icon
    self.forgotIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_forgotPassword@%#3x"]];
    _forgotIcon.frame = CGRectMake(0, 0, 21, 21);
    _forgotIcon.alpha = 1;
    _forgotIcon.center = CGPointMake(WIDTH / 2 + 93 , 475);
    _forgotIcon.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_forgotIcon];
    _forgotIcon.center = CGPointMake(70, 475);
    [_forgotIcon setImage:[UIImage imageNamed:@"icon_delegate@#"]];
    // 注册代表你已同意
    self.agreeDelegateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 180, 50)];
    _agreeDelegateLabel.center = CGPointMake((_forgotPasswordButton.center.x - _forgotIcon.center.x) / 2 + _forgotIcon.center.x - 25, _forgotIcon.center.y);
    _agreeDelegateLabel.text = @"注册代表你已同意";
    _agreeDelegateLabel.font = [UIFont italicSystemFontOfSize:19];
    _agreeDelegateLabel.textColor = [UIColor whiteColor];
    _agreeDelegateLabel.textAlignment = 1;
    [self.view addSubview:_agreeDelegateLabel];
    _agreeDelegateLabel.backgroundColor = [UIColor clearColor];
    // 登录login
    self.loginButton = [UIButton createLoginButton];
    [self.view addSubview:_loginButton];
    [self.loginButton setTitle:@"注册" forState:0];
   
    // 注册register
    self.registerButton = [UIButton createRegisterButton];
    [self.view addSubview:_registerButton];
    [self.registerButton setTitle:@"返回登录" forState:0];
    // 到处溜达button
    self.lookAroundButton = [UIButton createLookAroundButton];
    [self.view addSubview:_lookAroundButton];
    
    // textField 的处理
    
    [self dealWithTextField];
    // 返回登录的处理
    [self backLogin];
    
    
    
    
}
- (void)backToRootViewController {
    [self dismissViewControllerAnimated:NO completion:^{
        
        
    }];
//    [self.navigationController popViewControllerAnimated:YES];
}
- (void)backLogin {
    [self.registerButton addTarget:self action:@selector(backToRootViewController) forControlEvents:UIControlEventTouchUpInside];
}
- (void)dealWithTextField{
    // textField签协议
    self.personTextfield.delegate = self;
    self.passwordTextfield.delegate = self;
    // 回收键盘
    // 左边图标变颜色
    // 键盘上升动画
    // 键盘下降动画
    
    
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (self.lagouIcon.center.y != HEIGHT / 3) {
        [UIView animateWithDuration:0.6 animations:^{
            
            //           self.lagouIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo_lagou@3x.png"]];
            //           self.lagouIcon.center = CGPointMake(WIDTH / 2, HEIGHT / 3);
            self.personTextfield.center = CGPointMake(WIDTH / 2, HEIGHT / 2);
            self.passwordTextfield.center = CGPointMake(WIDTH / 2, HEIGHT / 2 + 53 + 1.5);
            self.forgotPasswordButton.frame = CGRectMake(WIDTH - 20 - 80 - 40, 450, 120, 50);
            self.loginButton.center = CGPointMake(WIDTH / 2, 520 + 20);
            self.forgotIcon.center = CGPointMake(70, 475);
            self.agreeDelegateLabel.center = CGPointMake((_forgotPasswordButton.center.x - _forgotIcon.center.x) / 2 + _forgotIcon.center.x - 25, _forgotIcon.center.y);
            self.lagouIcon.frame = CGRectMake(163.833, 175.5, 86.3333, 139.667);
            
        }];
        
    }
    [textField resignFirstResponder];
    return YES;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if ([textField isEqual:self.personTextfield]) {
        [self.personTextfield.personImageView setImage:[UIImage imageNamed:@"icon_phone"]];
        [self.passwordTextfield.phoneImageView setImage:[UIImage imageNamed:@"icon_identify1"]];
    } else {
        [self.personTextfield.personImageView setImage:[UIImage imageNamed:@"icon_iphone1"]];
        [self.passwordTextfield.phoneImageView setImage:[UIImage imageNamed:@"icon_identify"]];
    }
    // 键盘上升
    
    // 给定动画
    [UIView animateWithDuration:0.4 animations:^{
        self.personTextfield.center = CGPointMake(WIDTH / 2, 210);
        self.passwordTextfield.center = CGPointMake(WIDTH / 2, 210 + 54.5);
        self.lagouIcon.frame = CGRectMake(self.lagouIcon.frame.origin.x + self.lagouIcon.frame.size.width / 2, self.lagouIcon.frame.origin.y, 0, 0);
        self.forgotIcon.center = CGPointMake(70, 210 + 54.5 + 60);
        self.forgotPasswordButton.center = CGPointMake(WIDTH - 20 - 40 - 20, 210 + 54.5 + 60);
        self.agreeDelegateLabel.center = CGPointMake((_forgotPasswordButton.center.x - _forgotIcon.center.x) / 2 + _forgotIcon.center.x - 25, 210 + 54.5 + 60);
        self.loginButton.center = CGPointMake(WIDTH / 2, 210 + 54.5 + 120);
    }];
    
    
    return YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
